<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button class="btn">按钮</button>
    <!-- 1.导入 -->
    <script src="./lib/axios.js"></script>

    <script>
       
        let btn = document.querySelector('.btn')

        btn.addEventListener('click', function () {
            // 2.调用axios,配置请求参数
            axios({
                method: 'get',
                url: 'http://www.liulongbin.top:3009/api/getbooks',
                // get请求可以传递 查询(query)参数,axios通过 params属性传递
                params: {
                    id: 2,
                    bookname: '红楼梦'
                }

                // 3.处理成功后的回调
            }).then(({data:res}) => {    // 解构脱壳
                console.log(res.data);
            })
        })

    </script>
</body>

</html>